package com.eastfair.point.comsumer;

import com.alibaba.fastjson.JSONObject;
import com.eastfair.point.PointKeyDefinition;
import com.eastfair.point.service.TestCollectionService;
import com.eastfair.core.point.BasePoint;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ConsumerListener {
    @Autowired
    TestCollectionService testCollectionService;


    @KafkaListener(topics = "${ef.kafka.point}",groupId = "${spring.application.name}")
    public void onMessage(String message) {
        // TODO: 2022/1/21 kafaka埋点记录处理
        BasePoint basePoint = JSONObject.parseObject(message, BasePoint.class);
        JSONObject jsonObject = (JSONObject) basePoint.getPointObj();
        String pointName = jsonObject.getString("pointName");
        if (pointName.equals(PointKeyDefinition.USER_LOGIN)) {
            //用户登录事件埋点
            testCollectionService.add(basePoint);
        }
    }
}
